﻿using mds.Common;
using mds.DFSClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mds.DFSWeb
{
    public class HomeController : Controller
    {       
        public ActionResult Retrieve(String fileName)
        {
            String dfsPath=null;
            DFSFile file = FileWebCache.Instance.Get(dfsPath);           
            if (file == null)
            {
                var service = ServiceFactory.Intance.CreateInstance<IDFSClient>(typeof(IDFSClient).FullName);
                var resultDfs = service.GetFile(file.GetDfsPath());
                if (resultDfs.ActionResult)
                FileWebCache.Instance.Store(file);
            }
            return File(file.FileData, file.FileExtension, file.FileFullName);
        }
        public ActionResult Download(String fileName)
        {
            String dfsPath = null;
            DFSFile file = FileWebCache.Instance.Get(dfsPath);
            if (file == null)
            {
                var service = ServiceFactory.Intance.CreateInstance<IDFSClient>(typeof(IDFSClient).FullName);
                var resultDfs = service.GetFile(file.GetDfsPath());
                if (resultDfs.ActionResult)
                FileWebCache.Instance.StoreDownload(file);
            }
            return File(file.FileData, file.FileExtension, file.FileFullName);
        }
    }
}
